home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / programming / c / supralib / developer / source.org / _subdir.c < prev    next >
C/C++ Source or Header  |  1999-06-14  |  2KB  |  79 lines

  1. /****************************************************************
  2. *
  3. *    ---------------
  4. *   * Supra library *
  5. *    ---------------
  6. *
  7. *   -- Subdir --
  8. *   Demonstration of RecDirInit(), RecDirNextTags, RecDirFree()
  9. *
  10. *   Usage: subdir path
  11. *   path = directory path to be examined (including with it's
  12. *   subdirs).
  13. *
  14. *   This program will scan files through the entire directory
  15. *   tree, starting from a provided path.
  16. *
  17. *
  18. *   ©1995 by Jure Vrhovnik -- all rights reserved
  19. *   jurev@gea.fer.uni-lj.si
  20. *
  21. *****************************************************************/
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <clib/exec_protos.h>
  26. #include <clib/dos_protos.h>
  27. #include <string.h>
  28.  
  29. #include <libraries/supra.h>
  30.  
  31.  
  32. struct RecDirInfo rdi;
  33. char path[50];
  34.  
  35. char full[200];
  36. LONG size, allsize=0, files=0;
  37. int pos;
  38.  
  39. main(int argc, char *argv[])
  40. {
  41. UBYTE err;
  42.  
  43.     if (argc == 0) {
  44.         printf("Enter directory to list: ");
  45.         gets(path);
  46.         rdi.rdi_Path = path;
  47.     } else rdi.rdi_Path = argv[1];
  48.  
  49.     rdi.rdi_Num = -1;       /* Unlimited number of subdirs deep */
  50.     rdi.rdi_Pattern = NULL; /* No pattern */
  51.  
  52.     if (RecDirInit(&rdi) == 0) {
  53.         printf("Scanning %s\n\n", rdi.rdi_Path);
  54.  
  55.         while ((err = RecDirNextTags(&rdi, NULL,
  56.                                     RD_FULL, full,
  57.                                     RD_SIZE, &size,
  58.                                     TAG_DONE)) == 0) {
  59.             pos = strlen(full)-25;
  60.             if (pos < 0) pos = 0;
  61.  
  62.             printf("%-25s%15ld\n", full+pos, size);
  63.             allsize += size;
  64.             files++;
  65.         }
  66.  
  67.         switch(err) {
  68.             case DN_ERR_END:
  69.                 printf("\n%ld files -- %ld bytes listed\n", files, allsize);
  70.                 break;
  71.             default:
  72.                 printf("error, terminating...\n");
  73.         }
  74.     } else {
  75.         printf("Path not found.\n");
  76.     }
  77. }
  78.  
  79.